<template>
      <el-dialog
  title="提示"
  :visible="dialogVisible"
  width="70%"
  @close="colseDialog"
  @open='open'
  >
  <!-- 内容区域 -->
  <el-row>
        <el-col :span="6">【题型】：{{myData.questionType|questionTypes}}</el-col>
        <el-col :span="6">【编号】：{{myData.id}}</el-col>
        <el-col :span="6">【难度】：{{myData.difficulty|difficultys}}</el-col>
        <el-col :span="6">【标签】：{{myData.tags}}</el-col>
        <el-col :span="6">【学科】：{{myData.subjectName}}</el-col>
        <el-col :span="6">【目录】：{{myData.directoryName}}</el-col>
        <el-col :span="6">【方向】：{{myData.direction}}</el-col>
      </el-row>
      <hr>
      【题干】：<div v-html="myData.question" style="color:blue"></div>
      <div v-if="myData.questionType!=='3'">
        <div style="padding-bottom:5px">{{myData.questionType}} 选项：（以下选中的选项为正确答案）</div>
        <div v-for="item in myData.options" :key="item.code" style="padding:8px 0">
          <el-radio v-if="myData.questionType==='1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox v-if="myData.questionType==='2'" :value="item.isRight?true:false" >{{item.title}}</el-checkbox>
        </div>
      </div>
      <hr>
      【参考答案】：<el-button type="danger" size="small" @click="preivewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="myData.videoURL" controls></video>
      </div>
      <hr>
      【答案解析】：<div style="display:inline-block" v-html="myData.answer"></div>
      <hr>
      【题目备注】：{{myData.remarks}}
  <!-- 关闭按钮 -->
  <span slot="footer" >
    <el-button type="primary" @click="colseDialog">关闭</el-button>
  </span>
</el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
import { difficulty, questionType } from '@/api/hmmm/constants'
export default {
  name: 'Dialog',
  props: {
    // 控制对话框
    dialogVisible: {
      type: Boolean,
      default: false
    },
    // 基础信息
    subject: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      // 获取数据
      close: false,
      myData: {},
      // 视频开关
      play: false
    }
  },
  filters: {
    //
    difficultys(value) {
      if (value) return difficulty.find(item => item.value === +value).label
    },
    questionTypes(value) {
      if (value) return questionType.find(item => item.value === +value).label + '题'
    }
  },
  methods: {
    // 关闭对话框
    colseDialog() {
      this.$emit('update:dialogVisible', false)
      // 重置对话框
      // 暂停视频
      this.$refs.video.pause()
      // 关闭视频
      this.play = false
    },
    // 打开对话框的回调函数
    async open() {
      const { data } = await detail({ id: this.subject.id })
      console.log(data)
      this.myData = data
    },
    preivewVideo() {
      this.play = true
      this.$refs.video.play()
    }
  }
}
</script>

<style>

</style>
